<?php
session_start() ;
if(!isset($_SESSION["login"]) || $_SESSION["login"] == "")
{   
  header("Location: index.php?error=4") ;
}
require("fonctions.php");

	$sql="select * from distributeurs order by codesap";
	$res = mysql_query($sql) or die("$sql");
	
	


 		header("Pragma: public");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");;
        header("Content-Disposition: attachment;filename=liste_etablissement.csv ");
        header("Content-Transfer-Encoding: binary ");

        echo "CodeSap;D&eacute;nomination;Groupe;Zone;R&eacute;seau;Identifiant;Mot de passe; \n";
        while($row = mysql_fetch_object($res)){
        	
        	$zone = getZoneNameById($row->id_zone);
        	$reseau = getReseauNameById($row->id_reseau);
        	
        	echo "$row->codesap ; $row->nom;$row->groupe;$zone;$reseau;$row->login;$row->password \n";
        }

 ?>